import { getToken } from "@/utils/auth";
import $api from '@/api/request/index.js';

const state = () => ({
	userInfo: {
		role: ''
	}
});

const mutations = {
	GET_USERINFO(state, userInfo) {
		state.userInfo = userInfo;
	}
};

const actions = {
	getUserInfo({commit}) {
		return new Promise((resolve) => {
			if(!getToken()){
				resolve();
				return true;
			}
			$api("user.info").then((res) => {
				commit('GET_USERINFO', res.data || { role: "" });
				resolve();
			});
		});
	}
}

export default {
	namespaced: true,
	state,
	mutations,
	actions
}
